#pragma once

#include "../../foundation/include/eveCommon.h"
#include "../../foundation/include/eveDataStream.h"
#include "../../foundation/include/eveStringUtil.h"
#include "../../foundation/include/eveMath.h"

#include "d3d9.h"
#include "d3dx9.h"

typedef IDirect3D9		  ID3D;
typedef IDirect3DDevice9  ID3DDevice;
typedef IDirect3DTexture9 ID3DTexture;
typedef IDirect3DVertexBuffer9 ID3DVertexBuffer;

const size_t MAXGROUPFREETEXTURENUM = 32;
const uint16 TEXTUREWIDTH = 256;
const uint16 TEXTUREHEIGHT = 256;

inline uint8 GetBlockNum(uint16 size,uint16 base = TEXTUREWIDTH) 
{
	assert(base);
	return (size + base - 1)/base;
}
inline D3DFORMAT GetFormat(DWORD pixelbits)
{
	switch(pixelbits)
	{
	case 32:
		return D3DFMT_A8R8G8B8;
	case 24:
		return D3DFMT_R8G8B8;
	}
	return D3DFMT_R8G8B8;
}

inline D3DFORMAT GetTextureFormat(uint8 pixelbits)
{
	switch(pixelbits)
	{
	case 32:
		return D3DFMT_A8R8G8B8;
	case 24:
		return D3DFMT_R8G8B8;
	}
	return D3DFMT_R8G8B8;
}

inline uint16 GetTailWidth(uint16 size)
{
	size &= (TEXTUREWIDTH-1);
	return (size != 0 ? size : TEXTUREWIDTH);

}

#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
